package grg.learn.compose.ui.ui.main

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import grg.learn.compose.ui.models.MainListVM
import grg.learn.compose.ui.theme.Theme

@Composable
fun Index(theme: Theme,mainListData:MainListVM) {

    val list by mainListData.datas2.collectAsState(initial = ArrayList<String>())
    //Composable calls are not allowed inside the calculation parameter of inline fun <T>
    // remember(calculation: () -> TypeVariable(T)): TypeVariable(T)

    LazyColumn(content = {
        items(
            list.size
        ) {
            IndexListItem(model = list[it], theme)
        }

    })


}

@Composable
fun IndexListItem(model: String, theme: Theme) {
    Box(
        Modifier
            .fillMaxWidth()
            .height(50.dp),
        contentAlignment = Alignment.CenterStart
    ) {
        BasicText(
            text = model,
            style = TextStyle(
                color = theme.primaryTextColor,
                fontSize = theme.primaryTextSize
            )
        )
    }
}
